package com.demo.core.model.support;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 一般执行结果模型
 * 为Dao层直接执行Sql后,提供数据存储模型
 * 将使用Map作为容器,兼顾一般数据模型SimpleBaseModel
 * 方便以Sql语句直接查询数据,并且对查询的数据进行分页,排序.
 * 参照@see com.demo.core.dao.base.support.SearchDaoSupport
 *    @see com.demo.core.dao.impl.base.PageCoreDaoSupport
 *    
 * @author ryuu.kk
 *
 */
public class GeneralMapModel<K extends java.io.Serializable, V> extends SimpleBaseModel implements Map<K, V> {

	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = 436780546662209467L;
	
	/**
	 * 存储Map对象 
	 */
	private Map<K, V> _values = new HashMap<K, V>(23);
	
	public Long getId() {
		if (pk == null) {
			V value = _values.get("id");
			if (value instanceof Long) {
				pk = (Long) value;
			}
		}
		return pk;
	}
	
	public void setId(Long id) {
		pk = id;
	}
	
	@Override
	public int size() {
		return _values.size();
	}

	@Override
	public boolean isEmpty() {
		return _values.isEmpty();
	}

	@Override
	public boolean containsKey(Object key) {
		return _values.containsKey(key);
	}

	@Override
	public boolean containsValue(Object value) {
		return _values.containsValue(value);
	}

	@Override
	public V get(Object key) {
		return _values.get(key);
	}

	@Override
	public V put(K key, V value) {
		return _values.put(key, value);
	}

	@Override
	public V remove(Object key) {
		return _values.remove(key);
	}

	@Override
	public void putAll(Map<? extends K, ? extends V> m) {
		_values.putAll(m);
	}

	@Override
	public void clear() {
		_values.clear();
	}

	@Override
	public Set<K> keySet() {
		return _values.keySet();
	}

	@Override
	public Collection<V> values() {
		return _values.values();
	}

	@Override
	public Set<java.util.Map.Entry<K, V>> entrySet() {
		return _values.entrySet();
	}
}
